from typing import List

class Solution:
    def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:
        r0 = [n - nums[0] for n in nums]
        s = sum(r0)
        p = 0
        res = [s]
        for i in range(1, len(nums)):
            p += (nums[i] - nums[i-1]) * i
            s -= r0[i-1]
            e = p + s - r0[i] * (len(nums) - i)
            res.append(e)
        return res


if __name__ == '__main__':
    s = Solution()
    print(s.getSumAbsoluteDifferences([2,3,5]))
    print(s.getSumAbsoluteDifferences([1,4,6,8,10]))
